package es.us.lsi.aws.api.model;

import java.util.List;

import com.google.appengine.api.datastore.Entity;
import com.google.gson.Gson;

import es.us.lsi.aws.api.util.Pair;

public class User {

	private String username;
	private String password;
	private List<Pair<String, String>> lstSocialAccount;

	@SuppressWarnings("unchecked")
	public User(Entity ent) {
		Gson gson = new Gson();
		new User((String) ent.getProperty("username"),
				(String) ent.getProperty("password"), gson.fromJson(
						(String) ent.getProperty("lstSocialAccount"),
						List.class));
	}

	public User(String username, String password,
			List<Pair<String, String>> lstSocialAccount) {
		super();
		this.username = username;
		this.password = password;
		this.lstSocialAccount = lstSocialAccount;
	}

	public Entity createEntity() {
		Entity ent = new Entity(this.getClass().getSimpleName());
		ent.setProperty("text", this.getUsername());
		ent.setProperty("sent", this.getPassword());
		Gson gson = new Gson();
		ent.setProperty("lstSocialAccount",
				gson.toJson(this.getLstSocialAccount()));

		return ent;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public List<Pair<String, String>> getLstSocialAccount() {
		return lstSocialAccount;
	}

	public void setLstSocialAccount(List<Pair<String, String>> lstSocialAccount) {
		this.lstSocialAccount = lstSocialAccount;
	}
}
